﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" 
CodeFile="ParentChild.aspx.cs" Inherits="ParentChild" %>

<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>

<asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

   
    <h2 class="DDSubHeader">Parent Table: <%= EntityDataSource1.GetTable().DisplayName%></h2>
    
    <div class="ExampleView"> 
    	On any row in the <code><%=EntityDataSource1.GetTable().DisplayName%></code> parent table click 
        select to filter the rows in the <code><%=EntityDataSource2.GetTable().DisplayName%></code> child 
        table. <br /> 
        The example uses the  
    	<a href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.controlfilterexpression(VS.100).aspx" target="_blank">
    	<code>System.Web.DynamicData.ControlFilterExpression</code></a> control to filter the rows 
        in the child table. 
    	<br />
    	See also <a href="http://msdn.microsoft.com/en-us/library/dd985039(VS.100).aspx#"  target="_blank">
        Walkthrough:Filtering Rows in Tables that Have a Parent-Child Relationship.</a>
    </div>
    
    <hr />
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                HeaderText="Vui lòng sửa lại các lỗi dưới đây" />
            <asp:DynamicValidator runat="server" ID="GridView1Validator" ControlToValidate="GridView1" Display="None" />
            <asp:DynamicValidator runat="server" ID="GridView2Validator" ControlToValidate="GridView2" Display="None" />

            <asp:GridView ID="GridView1" runat="server" DataSourceID="EntityDataSource1" 
                EnablePersistedSelection="true"
                AutoGenerateSelectButton="true" 
                AutoGenerateEditButton="True" 
                AutoGenerateDeleteButton="true"
                AllowPaging="True" AllowSorting="True" 
                OnDataBound="OnGridViewDataBound"
                OnSelectedIndexChanging="OnGridViewSelectedIndexChanging"
                
                OnRowCreated="OnGridViewRowCreated" CssClass="DDGridView">

                <PagerStyle CssClass="footer" />        
                <SelectedRowStyle CssClass="selected" />
                <PagerTemplate>
                    <asp:GridViewPager runat="server" />
                </PagerTemplate>
                <EmptyDataTemplate>
                    Chưa có dữ liệu.
                </EmptyDataTemplate>
            </asp:GridView>
            
            <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
                EnableDelete="True" EnableUpdate="True" 
                ContextTypeName="AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities" 
                EnableFlattening="False" 
                EntitySetName="ProductCategories"  />

            <br />
            <hr />
            <br/>
            
            <h2 class="DDSubHeader">Child Table:<%=EntityDataSource2.GetTable().DisplayName%></h2>
            <asp:Panel ID="DetailsPanel" runat="server">
           
                <asp:GridView ID="GridView2" runat="server" 
                    DataSourceID="EntityDataSource2" 
                    AutoGenerateDeleteButton="true" AutoGenerateEditButton="true"
                    AllowPaging="true" AllowSorting="true" 
                    OnPreRender="OnDetailsViewPreRender" CssClass="DDGridView">
                    <EmptyDataTemplate>
                        No items matching the given criteria.
                    </EmptyDataTemplate>
                    <PagerTemplate>
                        <asp:GridViewPager ID="GridViewPager1" runat="server" />
                    </PagerTemplate>
                    <PagerStyle CssClass="footer" />        
                </asp:GridView>
            
                
                <asp:EntityDataSource ID="EntityDataSource2" runat="server" 
                EnableDelete="True" EnableUpdate="True" EnableInsert="true"
                ContextTypeName="AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities" 
                EnableFlattening="False" 
                EntitySetName="Products"  />

                <asp:QueryExtender ID="QueryExtenderID" 
                    TargetControlID="EntityDataSource2" runat="server">
                    <asp:ControlFilterExpression ControlID="GridView1" 
                    Column="ProductCategory" />
                </asp:QueryExtender>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

